<?php
require_once($_SESSION["root_path"]."/DataBase.inc");
require_once($_SESSION["root_path"]."/general_queries.inc");

$programs = query_programs()->execute();


echo "<b>Status:</b><ul style='margin:0px'>";

echo "<li>Number of eligible applicants: ";
$q_eligibles = "SELECT COUNT(*) FROM applicant";
$where_eligibles = "";
foreach ($programs as $p) {
	$q_eligibles .= " LEFT JOIN applicant_eligibility AS eligibility_".$p["program_id"]." ON (eligibility_".$p["program_id"].".applicant_id=applicant.applicant_id AND eligibility_".$p["program_id"].".program_id=".$p["program_id"].")";
	if ($where_eligibles <> "") $where_eligibles .= " OR ";
	$where_eligibles .= "eligibility_".$p["program_id"].".eligible=1";
}
$where_eligibles = "applicant.excluded=0 AND applicant.selection_campaign_id=".$_SESSION["campaign_id"]." AND (".$where_eligibles.")"; 
$result = DataBase::query($q_eligibles." WHERE ".$where_eligibles);
$nb_eligibles = $result == false ? 0 : $result[0][0];
echo $nb_eligibles."</li>";

echo "<li>Number of eligible applicants assigned to an interview center: ";
$q_assigned_to_ic = $q_eligibles." LEFT JOIN applicant_interview ON applicant_interview.applicant_id=applicant.applicant_id";
$where_assigned_to_ic = $where_eligibles." AND applicant_interview.interview_center_id IS NOT NULL";
$result = DataBase::query($q_assigned_to_ic." WHERE ".$where_assigned_to_ic);
$nb_assigned_to_ic = $result == false ? 0 : $result[0][0];
echo "<span style='color:".($nb_assigned_to_ic == $nb_eligibles ? "green" : "red")."'>".$nb_assigned_to_ic."</span></li>";

echo "<li>Number of eligible applicants assigned to an interview center and having an interview plan: ";
$q_interview_plan = $q_assigned_to_ic;
$where_interview_plan = $where_assigned_to_ic." AND applicant_interview.interview_id IS NOT NULL";
$result = DataBase::query($q_interview_plan." WHERE ".$where_interview_plan);
$nb_interview_plan = $result == false ? 0 : $result[0][0];
echo "<span style='color:".($nb_assigned_to_ic == $nb_interview_plan ? "green" : "red")."'>".$nb_interview_plan."</span></li>";

echo "</ul>";
?>